package ar.edu.unq.tpi.uis.tepe3.wicket.panels;

import javax.swing.tree.DefaultMutableTreeNode;

import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;

import ar.edu.unq.tpi.uis.tepe3.dominio.Folder;
import ar.edu.unq.tpi.uis.tepe3.wicket.AbstractListPage;
import ar.edu.unq.tpi.uis.tepe3.wicket.pages.AccessListPage;
import ar.edu.unq.tpi.uis.tepe3.wicket.pages.FolderFormPage;

public class FolderPropertyTreeTableActionsPanel extends Panel {

	public FolderPropertyTreeTableActionsPanel(String id, final IModel inputModel){
		
			super(id);
			
	        // **********************************
			// ** Link para editar los objetos
			// **********************************
	        Link editLink = new Link("editLink", inputModel) {
				
				@Override
				public void onClick() {					
					this.setResponsePage(new FolderFormPage(new CompoundPropertyModel(((DefaultMutableTreeNode)getModelObject()).getUserObject())));
				}
			}; 

	        add(editLink);
	        
	        Link deleteLink = new Link("deleteLink", inputModel){
	        	
				@Override
				public void onClick() {
					((AbstractListPage) getPage()).deleteAction(inputModel);
				}
	        	
	        };
	        
	        add(deleteLink);
	        Link permissionManagerLink = new Link("permissionLink",inputModel) {
				
				@Override
				public void onClick() {
					// TODO Auto-generated method stub
					Folder aFolder = (Folder) ((DefaultMutableTreeNode) getModelObject()).getUserObject();
					this.setResponsePage(new AccessListPage(new CompoundPropertyModel(aFolder)));
				}
			};
			add(permissionManagerLink);
	}
}
